import java.util.*;

public class Process 
{
	private ArrayList<ICycle> 	m_cycles;
	private boolean				m_isWaiting;
	
	public Process()
	{
		m_cycles 	= new ArrayList<ICycle>();
		m_isWaiting = false;
	}
	
	public void addCycle(ICycle cycle)
	{
		m_cycles.add(cycle);
	}
	
	public long numCycles()
	{
		return m_cycles.size();
	}
	
	private void consumeCycle()
	{
		ICycle cycle = m_cycles.remove(0);
		m_isWaiting = cycle instanceof IOCycle;
	}
	
	public boolean isDone()
	{
		return m_cycles.isEmpty();
	}
	
	public boolean isWaiting()
	{
		return m_isWaiting && !isDone();
	}
	
	public void execute()
	{
		// TODO: assert if no cycles pending
		if (numCycles() > 0)
		{
			consumeCycle();
		}
	}
}
